package com.zhongge.book;

import java.time.LocalDate;

/**
 * @ClassName Book
 * @Description TODO 图书类
 * @Author zhongge
 * @Version 1.0
 */
@SuppressWarnings("all")
public class Book implements Comparable<Book>{
    private int bookId;//图书id
    private String title;//书名
    private String author;//作者
    private String type;//书本种类
    private int publishYear;//出版年份
    private boolean isBorrow;//借阅状态
    private int borrowCount;//借阅次数
    private LocalDate shelfDate;//上架时间

    /**
     * 构造方法
     * @param bookId 书本id
     * @param title 书名
     * @param author 作者
     * @param type 类型
     * @param publishYear 出版年份
     * @param shelfDate 上架时间
     * 其中isBorrow和borrowCount是不知道的 他们就使用默认值
     * 还有bookId你在初始化的时候是无法确定的
     */
    public Book(String title, String author, String type, int publishYear, LocalDate shelfDate) {
        this.title = title;
        this.author = author;
        this.type = type;
        this.publishYear = publishYear;
        this.shelfDate = shelfDate;
    }


    /*****************get和set方法*******************/
    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {
        this.bookId = bookId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPublishYear() {
        return publishYear;
    }

    public void setPublishYear(int publishYear) {
        this.publishYear = publishYear;
    }

    public boolean isBorrow() {
        return isBorrow;
    }

    public void setBorrow(boolean borrow) {
        isBorrow = borrow;
    }

    public int getBorrowCount() {
        return borrowCount;
    }

    public void setBorrowCount(int borrowCount) {
        this.borrowCount = borrowCount;
    }

    public LocalDate getShelfDate() {
        return shelfDate;
    }

    public void setShelfDate(LocalDate shelfDate) {
        this.shelfDate = shelfDate;
    }
    /**********************end**********************/


    /****************对借阅次数的增加和减少***********/
    /**
     * 借阅次数增加
     */
    public void increaseBorrwoCount() {
        this.borrowCount++;
    }

    /**
     * 借阅次数减少
     */
    public void reduceBorrwoCount() {
        this.borrowCount--;
    }

    /**********************end**********************/


    /**********************toJson*******************/
    //将对象序列化为字符串

    /**
     * 将对象序列化为数组
     * @return 字符串
     */
    public String toJson() {
        StringBuilder sb = new StringBuilder();
        sb.append(bookId).append(",");
        sb.append(title).append(",");
        sb.append(author).append(",");
        sb.append(type).append(",");
        sb.append(publishYear).append(",");
        sb.append(isBorrow).append(",");
        sb.append(borrowCount).append(",");
        sb.append(shelfDate);
        return sb.toString();
    }
    /**********************end**********************/

    /**********************compareTo*****************/
    //用于查看最受欢迎前n本书的时候的比较
    @Override
    public int compareTo(Book o) {
        return o.borrowCount - this.borrowCount;
    }

    /**********************end**********************/

    /**
     * 显示图书信息
     * @return String
     */
    @Override
    public String toString() {
        return "Book{" +
                "bookId=" + bookId +
                ", title='" + title + '\'' +
                ", author='" + author + '\'' +
                ", type='" + type + '\'' +
                ", publishYear=" + publishYear +
                ", isBorrow=" + isBorrow +
                ", borrowCount=" + borrowCount +
                ", shelfDate=" + shelfDate +
                '}';
    }


}
